package com.jinxi.controller;
import com.jinxi.req.CategoryQueryReq;
import com.jinxi.req.CategorySaveReq;
import com.jinxi.resp.CommonResp;
import com.jinxi.resp.CategoryQueryResp;
import com.jinxi.resp.PageResp;
import com.jinxi.service.CategoryService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private  CategoryService categoryService;

    @GetMapping("/list")
    public  CommonResp list(@Valid CategoryQueryReq req){
        CommonResp<PageResp<CategoryQueryResp>> resp = new CommonResp<>();
        PageResp<CategoryQueryResp> list=categoryService.list(req);
        resp.setContent(list);
        return resp;
    }

    @GetMapping("/all")
    public  CommonResp all(){
        CommonResp<List<CategoryQueryResp>> resp = new CommonResp<>();
        List<CategoryQueryResp> list=categoryService.all();
        resp.setContent(list);
        return resp;
    }
    @PostMapping ("/save")
    public  CommonResp save(@Valid @RequestBody CategorySaveReq req){
        CommonResp resp = new CommonResp<>();
        categoryService.save(req);
        return resp;
    }

    @DeleteMapping ("/delete/{id}")
    public  CommonResp delete(@PathVariable Long id){
        CommonResp resp = new CommonResp<>();
        categoryService.delete(id);
        return resp;
    }
}

